/*
 * @Author: 詹真琦(legendryztachi@gmail.com)
 * @Date: 2022-03-23 16:03:35
 * @LastEditors: 詹真琦(legendryztachi@gmail.com)
 * @LastEditTime: 2022-03-23 16:20:46
 * @FilePath: \code\cwp-front\pc-collaboration\src\components\atom\at-who\helper.js
 * @Description: @人相关操作
 */
// 引入基础数据
import { useBaseInfoWithOut } from '@/store/modules/base-info.js';
/**
 * @description: 将字符串内的提及人列表提取出来与数据列表里面的比对。如果有就选中
 * @param {String}文本的字符串
 * @return {Array}提及人列表
 */
const match = /@(\S*)(\s|$)/g;
export function getMentionList(textString) {
    //姓名列表
    let nameList = [];
    let m = [];
    while ((m = match.exec(textString))) {
        const name = m[1];
        if (name) {
            nameList.push(name);
        }
    }
    //如果为空就返回空
    if (!nameList.length) return [];
    //去重
    nameList = Array.from(new Set(nameList));

    const result = [];

    //检测是否存在用户名，存在就加入列表
    const useBaseInfo = useBaseInfoWithOut();
    useBaseInfo.pushPeopleList.forEach((d) => {
        const index = nameList.findIndex((dd) => dd === d.memberName);
        //存在就加进去
        if (index > -1) {
            result.push(d);
            //从数组去除
            nameList.splice(index, 1);
        }
    });
    return result;
}
